home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / glob.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  2KB  |  78 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import os
  5. import fnmatch
  6. import re
  7. __all__ = [
  8.     'glob',
  9.     'iglob']
  10.  
  11. def glob(pathname):
  12.     return list(iglob(pathname))
  13.  
  14.  
  15. def iglob(pathname):
  16.     if not has_magic(pathname):
  17.         if os.path.lexists(pathname):
  18.             yield pathname
  19.         
  20.         return None
  21.     
  22.     (dirname, basename) = os.path.split(pathname)
  23.     if not dirname:
  24.         for name in glob1(os.curdir, basename):
  25.             yield name
  26.         
  27.         return None
  28.     
  29.     if has_magic(dirname):
  30.         dirs = iglob(dirname)
  31.     else:
  32.         dirs = [
  33.             dirname]
  34.     if has_magic(basename):
  35.         glob_in_dir = glob1
  36.     else:
  37.         glob_in_dir = glob0
  38.     for dirname in dirs:
  39.         for name in glob_in_dir(dirname, basename):
  40.             yield os.path.join(dirname, name)
  41.         
  42.     
  43.  
  44.  
  45. def glob1(dirname, pattern):
  46.     if not dirname:
  47.         dirname = os.curdir
  48.     
  49.     
  50.     try:
  51.         names = os.listdir(dirname)
  52.     except os.error:
  53.         return []
  54.  
  55.     if pattern[0] != '.':
  56.         names = filter((lambda x: x[0] != '.'), names)
  57.     
  58.     return fnmatch.filter(names, pattern)
  59.  
  60.  
  61. def glob0(dirname, basename):
  62.     if basename == '':
  63.         if os.path.isdir(dirname):
  64.             return [
  65.                 basename]
  66.         
  67.     elif os.path.lexists(os.path.join(dirname, basename)):
  68.         return [
  69.             basename]
  70.     
  71.     return []
  72.  
  73. magic_check = re.compile('[*?[]')
  74.  
  75. def has_magic(s):
  76.     return magic_check.search(s) is not None
  77.  
  78.